﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SportsPlatform.Query.SportBusiness.Employee;
using SportsPlatform.Dto.SportBusiness.Employee;
using SportsPlatform.Base;
using SportsPlatform.WeChat.IWeChat;
using Nest;
using SportsPlatform.Application.Query.SportBusiness.Employee;
using Microsoft.AspNetCore.Authorization;

namespace SportsPlatform.Controllers
{
    /// <summary>
    /// 移动端用户登录注册接口
    /// </summary>
    [Route("api/[controller]/[action]")]
    [AllowAnonymousAttribute]
    public class WeChatLoginController : SportsPlatformControllerBase
    {
        private ILoginService _loginService;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="loginService"></param>
        public WeChatLoginController(ILoginService loginService)
        {
            _loginService = loginService;
        }

        /// <summary>
        /// 注册接口
        /// </summary>
        /// <param name="employeeRegisterQuery"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<BaseResultDto> EmployeeRegister([FromBody] EmployeeRegisterQuery employeeRegisterQuery)
        {
            return await _loginService.EmployeeRegister(employeeRegisterQuery);
        }

        /// <summary>
        /// 登录接口
        /// </summary>
        /// <param name="employeeLoginQuery"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultDto<EmployeeDto>> EmployeeLogin([FromBody] EmployeeLoginQuery employeeLoginQuery)
        {
            return await _loginService.EmployeeLogin(employeeLoginQuery);
        }

        /// <summary>
        /// 通过openId获取用户信息
        /// </summary>
        /// <param name="openId"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultDto<EmployeeDto>> GetByOpenId([FromBody] GetOpenIdQuery query)
        {
            return await _loginService.GetByOpenId(query);
        }

        /// <summary>
        /// 验证身份证号
        /// </summary>
        /// <param name="EmployeeId"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultDto<bool>> CheckIdNumber([FromBody] GetEmployeeIdQuery query)
        {
            return await _loginService.CheckIdNumber(query.EmployeeId);
        }
    }
}
